package test.lyj;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


import test.lyj.model.ListAdapter;
import test.lyj.tool.Tool;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;

public class FooterListActivity extends ListActivity{
	private ListView listView;
	private int curNum,maxNum,chooseLine;
	ArrayList<HashMap<String,Object>> allDataInPage;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Log.d("footertest", "startOnCreate");
		setContentView(R.layout.footer_list_window);
		Log.d("footertest", "startWindowSwithe");
		
		Button logonButton = (Button) findViewById(R.id.btn_logon);
//		listView = (ListView) findViewById(R.id.listview);
		listView=getListView();
		View listFooter = (LinearLayout) LayoutInflater.from(this).inflate(   
                R.layout.list_base_footer_item, null);   
        listView.addFooterView(listFooter);// 添加FooterView   
		allDataInPage=Tool.getStaticMap(this,0,9); 
		curNum=9;  
		maxNum=21;
		ListAdapter listAdapter=new ListAdapter(FooterListActivity.this, allDataInPage, R.layout.list_base_window_item, new String[]{"icon","name","address"}, new int[]{R.id.item_image,R.id.item_name,R.id.item_address});
		listView.setAdapter(listAdapter);
//		listView.setOnScrollListener(this);
		Log.d("footertest", "getListView");
		//增加footer按钮，这里涉及到动态增加layout
		/*LayoutInflater infla = LayoutInflater.from(this);   
	      View footView = infla.inflate(R.layout.list_base_footer_item, null);  */
		
	        
	     /* View footView = ((LayoutInflater) this     
	    		     
	    		  .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(     
	    		       
	    		  R.layout.list_base_footer_item, null, false);*/
	    		 
	      
	     //listView.addFooterView(footView, null, true);
	     // listView.addFooterView(footView, null, true);
	     Log.d("footertest", "getListViewend");
	   /*
		//添加item事件
		listView.setOnItemClickListener(new OnItemClickListener() {
			
			/** 
			 * 在listview中增加item的点击事件，涉及到将item中的元素显示出来
			 *//*
			@Override
				
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {//这里的arg1就是listAdapter中传入的布局，即R.layout.list_base_window_item
				LinearLayout itemLayout=(LinearLayout)arg1;
				TextView nameView= (TextView) itemLayout.findViewById(R.id.item_name);
				
				Tool.showMsgDialog(FooterListActivity.this, arg3+"有戏？"+nameView.getText());
			}
		});*/
		
		
	}
//	@Override
//	public void onScroll(AbsListView view, int firstVisibleItem,
//			int visibleItemCount, int totalItemCount) {
//		// TODO Auto-generated method stub
//		
//	}
//	@Override
//	public void onScrollStateChanged(AbsListView view, int scrollState) {
//		switch (scrollState) {
//		case OnScrollListener.SCROLL_STATE_IDLE:
//			// mBusy = false;
//			//int first = view.getFirstVisiblePosition();
////			int end = view.getLastVisiblePosition();
////			// int count = view.getChildCount();
////			int countall = view.getCount();
//
//			// mBusy = false;
//			int first = view.getFirstVisiblePosition();
//			int end = view.getLastVisiblePosition();
//			// int count = view.getChildCount();
//			int countall = view.getCount();//当前适配器有多少条（初始10条）
////			if(first==0)
////			 title = "电子名片-发件箱  ("+(first+1)+"/"+maxNum+")";
////			else
//			 //title = "电子名片-发件箱  ("+(end+1)+"/"+maxNum+")";	
//			
//			//setTitle(title);
//			Log.d("slip", "start addmoredata：end:"+end);
//			Log.d("slip", "start countall:"+countall);
//			Log.d("slip", "end == (countall - 1):"+(end == (countall - 1)));
//			if (end == (countall - 1) && curNum < maxNum) {
//				Log.d("slip", "start addmoredata："+end+"|"+curNum+"|"+maxNum+"|"+countall);
//				chooseLine = end;
//				addMoreData(curNum);
//				break;
//			}
//		}
//		
//	}
	private void addMoreData(int curNum) {
		ArrayList<HashMap<String,Object>> temp=Tool.getStaticMap(this,curNum+1,curNum+11);
		Log.d("slip", "temp.size="+temp.size());
		allDataInPage.addAll(temp);
		Log.d("slip", "allDataInPage="+temp.size());
		curNum=curNum+10;
		maxNum=21;
		ListAdapter listAdapter=new ListAdapter(FooterListActivity.this, allDataInPage, R.layout.list_base_window_item, new String[]{"icon","name","address"}, new int[]{R.id.item_image,R.id.item_name,R.id.item_address});
		listView.setAdapter(listAdapter);
		listView.setSelection(chooseLine);
		
	}
	
	

//	OnClickListener logonClicker = new OnClickListener() {
//
//		@Override
//		public void onClick(View v) {
//			Intent intent = new Intent();
//			intent.setClass(TestLyjLunch.this, ListBaseActivity.class);
//			startActivity(intent);
//			// TestLyjLunch.this.finish();
//
//		}
//	};

}
